package com.swak.frame.hystrix.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.swak.frame.ump.EventInfo;
import com.swak.frame.ump.adapter.AlarmEventAdapter;

@Component
public class HystrixAlarmEvent implements FallbackEvent {

    @Autowired
    private AlarmEventAdapter alarmEventAdapter;

    @Override
    public void event(HystrixEventInfo event) {
        EventInfo.Builder builder = new EventInfo.Builder();
        builder.info("[{}.{}] Hystrix circuit Breaker to fallback method:{}").bizTag("hystrix")
            .args(new Object[] {event.getTarget().getClass().getName(), event.getMethod().getName(),
                event.getFallbackMethod()});

        alarmEventAdapter.event(builder.build());
    }
}
